import { resolve } from 'path'
import { defineConfig, externalizeDepsPlugin } from 'electron-vite'
import vue from '@vitejs/plugin-vue'
import Unocss from 'unocss/vite'
import vueJsx from '@vitejs/plugin-vue-jsx'
import { createSvgIconsPlugin } from 'vite-plugin-svg-icons'
import { fileURLToPath, URL } from 'node:url'



export default defineConfig({
  main: {
    plugins: [externalizeDepsPlugin()
    ]
  },
  preload: {
    plugins: [
      externalizeDepsPlugin()
    ]
  },
  renderer: {
    resolve: {
      alias: {
        '@': resolve('src/renderer/src'),
        '#': fileURLToPath(new URL('./src/modules', import.meta.url))
      }
    },
    plugins: [
      vue(),
      vueJsx(),
      // 第二步：使用Unocss
      Unocss({
        // 可选：按需自定义规则
        rules: [
              [/^m-(\d+)$/, ([, d]) => ({ margin: `${d}px` })],
              [/^p-(\d+)$/, ([, d]) => ({ padding: `${d}px`})],
              [/^w-(\d+)$/, ([, d]) => ({ width: `${d}px`})]
          ]
      }),
      createSvgIconsPlugin({
        iconDirs: [fileURLToPath(new URL('./src/renderer/src/assets/svgIcons', import.meta.url))],
        symbolId: 'icon-[dir]-[name]',
        customDomId: '__svg__icons__dom__'
      })
    ]
  }
})
